package com.windbell;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.view.Window;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.windbell.net.NetTask;

public class ContentActivity extends Activity  {
	ListView listview;
	SimpleAdapter adapter;
	List array=new ArrayList();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_content);
		findViewById();
		CharSequence aurl=this.getIntent().getCharSequenceExtra("aurl");
		new NetTask(new NetTask.myProcess() {
			@Override
			public void process(String result) {
				try {
					JSONObject json =new JSONObject(result);
					JSONArray jsonArray=(JSONArray)json.get("body");
					array.clear();
					for(int i =0;i<jsonArray.length();i++){
						Map map = new HashMap();
						map.put("text",Html.fromHtml((String) jsonArray.get(i)));
						array.add(map);
					}
					adapter.notifyDataSetChanged();
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		}).execute("http://113.247.225.203:8080/serv/NewsAction?method=1&aurl="+aurl.toString());
	}

	private void findViewById() {
		listview =(ListView) findViewById(R.id.contentlistview);
		adapter = new SimpleAdapter(this, array,
				android.R.layout.simple_list_item_1,
				new String[] { "text" }, new int[] { android.R.id.text1 });
		listview.setAdapter(adapter);
	}
}
